//
// Created by LiuYou on 2021/5/13.
//

/*
 * 操作:
 *      size()
 *      empty()
 *      assign() 注意
 *      swap()
 *      front() 和vector用法一样
 *      back() 和vector用法一样
 */
#include <list>
#include <iostream>
#include "Todo.hpp"

typedef std::list<Todo> ListTodo;
using ListTODO = std::list<Todo>;

int main() {
    std::list<Todo> todoThings;
    std::cout << "todoThings.size(): " << todoThings.size() << std::endl;
    std::cout << "todoThings.empty(): " << todoThings.empty() << std::endl;

    Todo todo1("1", "1");
    Todo todo2("2", "2");
    Todo todo3("3", "3");
    Todo todo4("4", "4");
    todoThings.push_back(todo1);
    todoThings.push_back(todo2);
    todoThings.push_back(todo3);
    todoThings.push_back(todo4);
    // 和vector用法一样
    std::cout << todoThings.back() << std::endl;
    // 原来是可以对list进行 range-for 的。
    for (const auto& item : todoThings) {
        std::cout << item << std::endl;
    }
    std::cout << "todoThings.size(): " << todoThings.size() << std::endl;
    std::cout << std::endl;
    // This function fills a %list with __n copies of the given value.
    // 此函数使用给定值的__n个副本填充％list。
    // Note that the assignment completely changes the %list and that the resulting %list's size is the same as the number of elements assigned.
    // 请注意，分配完全更改了％list，并且所产生的％list的大小与分配的元素数相同。
    todoThings.assign(1, todo1);
    for (const auto& item : todoThings) {
        std::cout << item << std::endl;
    }
    std::cout << "todoThings.size(): " << todoThings.size() << std::endl;
    std::cout << std::endl;

    std::list<Todo> todos;
    todoThings.swap(todos);
    for (const auto& item : todoThings) {
        std::cout << item << std::endl;
    }
    std::cout << "todoThings.size(): " << todoThings.size() << std::endl;
    std::cout << std::endl;
    for (const auto& todo : todos) {
        std::cout << todo << std::endl;
    }
    std::cout << "todos.size(): " << todos.size() << std::endl;
    std::cout << std::endl;


    return 0;
}